var CCobjcode = "data-objcode";//自定义标签属性，用于对象取值

function getElNameAll(el){
    var name = el.attr('checkboxname') || el.attr('textboxname') || el.attr('radiobuttonname') 
    || el.attr('slidername') || el.attr('name');
    return name;
}

/**清空表单*/
zUtil.formClear = function(id){
    var opts ={
    };
    var ids = [];
    if("string" === $.type(id)){
        ids = id.split(",");
    }else{
        ids.push(id);
    }
    $.each(ids,function(i,idx){
        $(idx).form('clear');
        $(idx).find('table[id][class=datagrid-f]').each(function(i,e){
            try{
                zUtil.tableData(e,[]);
            }catch(b){
            }
        });
    });
};
/**校验表单*/
zUtil.formCheck = function(id){
    var ids = [];
    if("string" === $.type(id)){
        ids = id.split(",");
    }else{
        ids.push(id);
    }
    var flag = true;
    $.each(ids,function(i,idx){
        if(!$(idx).form('enableValidation').form('validate')){
            flag = false;
        }
    });
    return flag;
};
zUtil.formSubmit = function(id,options){
    var result = null;
    var opts = $.extend(true,{
        url: '',
        type: 'post',  
        dataType: 'json',        // 'xml', 'script', or 'json' (expected server response type)
        clearForm: true,        // clear all form fields after successful submit
        resetForm: true,        // reset the form after successful submit
        async: false,
//      timeout:   3000,
//      target:        '#output1',   // target element(s) to be updated with server response
//      beforeSubmit: function(formData, jqForm, options) {},  
        success: function(responseText, statusText, xhr, form){
            result = responseText;
        },
        error: function(xhr, status, err) {
            
        },
    }, options);
    $(id).ajaxSubmit(opts);
    return result;
}
/**下拉框*/
zUtil.formSelect = function(id,data){
    var ids = [];
    if("string" === $.type(id)){
        ids = id.split(",");
    }else{
        ids.push(id);
    }
    $.each(ids,function(i,idx){
        if($(idx).hasClass('combobox-f')){
            $(idx).combobox('loadData',data);
        }else if("SELECT" === $(idx).prop("tagName")){
            $(idx).empty();
            $(idx).append(data);
        }
    });
};
/**下拉框*/
zUtil.selectOn = function(id,func){
    var ids = [];
    if("string" === $.type(id)){
        ids = id.split(",");
    }else{
        ids.push(id);
    }
    $.each(ids,function(i,idx){
        if($(idx).hasClass('combobox-f')){
            $(idx).combobox('options').onSelect = func;
        }else{
            func($(idx).val());
        }
    });
};
/**下拉框*/
zUtil.selectClear = function(id){
    var ids = [];
    if("string" === $.type(id)){
        ids = id.split(",");
    }else{
        ids.push(id);
    }
    $.each(ids,function(i,idx){
        if($(idx).hasClass('combobox-f')){
            $(idx).combobox('loadData',[]);
        }else{
            $(idx).empty();
        }
        zUtil.val(idx,null);
    });
};
/**下拉框填充*/
zUtil.selectFill = function(fatherId,dictNames,dictData,options){
    if('undefined' !== $.type(dictNames)){
        $.each(dictNames,function(dicttype,keyname){
            var data = {};
            var tmp = [];
            var nms = keyname.split(",");
            $.each(nms,function(i,key){
                if(key.indexOf("#")!=-1){//ID
                    tmp.push(key);
                }else{//name
                    tmp.push(':input[class*=combobox-f][textboxname='+key+'], select[name='+key+']')
                }
            });
            var tobj = null;
            if(fatherId && fatherId!==''){
                tobj = $(fatherId).find(tmp.join(","));
            }else{
                tobj = $(tmp.join(","));
            }
            tobj.not("[class*=-value]").each(function(i,e){
                var name = getElNameAll($(e));
                if($(e).hasClass('combobox-f')){
                    if('undefined' === $.type(data['combobox'])){
                        data['combobox'] = zUtil.dataFormat(dictData[dicttype],0);
                    }
                    zUtil.formSelect(e,data['combobox']);
                }else {
                    if('undefined' === $.type(data['select'])){
                        data['select'] = zUtil.dataFormat(dictData[dicttype],1);
                    }
                    zUtil.formSelect(e,data['select']);
                }
            });
            data = null;
        });
    }
};
//数据格式转换
zUtil.dataFormat = function(dicts,waytype,option){
    function getLabel(nlabel){
       if('object' === $.type(nlabel)){
         if(nlabel["labelCode"]){
             nlabel = nlabel["labelCode"];
         }else if(nlabel["text"]){
             nlabel = nlabel["text"];
         }
       }
       return nlabel;
    }
    if(0 === waytype){//easyui下拉框转换
        var data = [];
        if('undefined' !== $.type(dicts) && dicts !== null){
             $.each(dicts,function(key,val){
               var label = getLabel(val);
               data.push({"text":label, "value":key});
             });
        }
        return data;
    }else if(1 === waytype){//常规下拉框转换
        var data = [];
        if('undefined' !== $.type(dicts) && dicts !== null){
             $.each(dicts,function(key,val){
               var label = getLabel(val);
               data.push('<option value="' + key + '">' + label + '</option>');
             });
        }
        return data;
    }else if(2 === waytype){
        var data = [];
        if('undefined' !== $.type(dicts) && dicts !== null){
             $.each(dicts,function(key,val){
               if('object' === $.type(val)){
                   val["valueCode"] = key;
                   data.push(val);
               }
             });
        }
        return data;
    }else if(3 === waytype){//转换为指定字段名称
        var data = [];
        var opts = $.extend(true,{
           getIdField: "value",
           getTextField: "text",
           setIdField: "value",
           setTextField: "text",
        },option);
        if('undefined' !== $.type(dicts) && dicts !== null){
             $.each(dicts,function(i,item){
                if('object' === $.type(item)){
                   var value = item[opts['getIdField']];
                   var text = item[opts['getTextField']];
                   var idField = opts["setIdField"];
                   var textField = opts["setIdField"];
                   data.push({
                       idField: value, textField: text
                   });
                }
             });
        }
        return data;
    }
};

zUtil.inputInit = function(id,type,option){
      if("input" == type){
        var opts = $.extend(true,{
            
        },option);
        $(id).textbox(opts);
      }
      else if("tag" == type){
         var opts = $.extend(true,{
                
         },option);
         $(id).tagbox(opts);
      }
      else if("check" == type){
        var opts = $.extend(true,{
                labelPosition: "after", //'before','after','top'
                labelAlign: "left", //'left','right'
                labelWidth: "auto",
//                data: [{"label":"选项1","value":"1"},{"label":"选项2","value":"2"}]
        },option);
        var datas = opts['data'];
        if(datas && datas.length>0){
            var cp = $(id).parent('.input-g');
            var tid = $(id).attr('id');
            $.each(datas,function(i,item){
                   var ct = cp.clone();
                   ct.children().attr('id',tid+(i+1));
                   cp.parent().append(ct);
            });
            $(cp).remove();
            $.each(datas,function(i,item){
                opts['label'] = item['label'];
                opts['value'] =item['value'];
                $(id+(i+1)).checkbox(opts);
            });
        }else{
           $(id).checkbox(opts);
        }
      }
      else if(type.indexOf("check-") != -1){
//          options     none     返回属性对象。
//          setValue     value     设置复选框的值。
//          disable     none     禁用组件。
//          enable     none     启用组件。
//          check     none     选中组件。
//          uncheck     none     取消选中组件。
//          clear     none     清空选中值。
//          reset
          type = type.split("-")[1];
          return $(id).checkbox(type,option);
      }
      else if("radio" == type){
        var opts = $.extend(true,{
            labelPosition: "after", //'before','after','top'
            labelAlign: "left", //'left','right'
            labelWidth: "auto",
//            data: [{"label":"选项1","value":"1"},{"label":"选项2","value":"2"}]
        },option);
        
        var datas = opts['data'];
        if(datas && datas.length>0){
            var cp = $(id).parent('.input-g');
            var tid = $(id).attr('id');
            $.each(datas,function(i,item){
                   var ct = cp.clone();
                   ct.children().attr('id',tid+(i+1));
                   cp.parent().append(ct);
            });
            $(cp).remove();
            $.each(datas,function(i,item){
                opts['label'] = item['label'];
                opts['value'] =item['value'];
                $(id+(i+1)).radiobutton(opts);
            });
        }else{
            $(id).radiobutton(opts);
        }
      }
      else if(type.indexOf("radio-") != -1){
//        options     none     返回属性对象。
//        setValue     value     设置复选框的值。
//        disable     none     禁用组件。
//        enable     none     启用组件。
//        check     none     选中组件。
//        uncheck     none     取消选中组件。
//        clear     none     清空选中值。
//        reset
        type = type.split("-")[1];
        return $(id).radiobutton(type,option);
    }
      else if("select" == type){
        var opts = $.extend(true,{
                
        },option);
        $(id).combobox(opts);
      }
      else if("cgrid" == type){
        var opts = $.extend(true,{
            delay: 50,
            data:[],
            idField: 'valueCode',
            textField: 'labelCode',
            method:"GET",
            columns: [[]],
            loadFilter: function(data){
                var tmp = {rows:[],total:0};
                try{//解析不了就原样返回
                    tmp.rows = data[zConst["resData"]][zConst["data"]];
                    tmp.total = data[zConst["resData"]][zConst["count"]];
                }catch(b){
                    return data;
                }
                return tmp;
             },
             onBeforeLoad: function(param){
                 try{//解析不了就原样返回
                     param[zConst["page"]] = param.page;
                     param[zConst["rows"]] = param.rows;
                 }catch(b){
                     return param;
                 }
                 return param;
            },
        },option);
        $(id).combogrid(opts);
    }
    else if(type.indexOf("cgrid-") != -1){
//        options,none     返回属性对象
//        grid,none     返回数据表格对象
//        setValues,values     设置组件值数组。
//        setValue,value     设置组件值。
//        clear,none     清除组件的值。
        type = type.split("-")[1];
        return $(id).combogrid(type,option);
    }
    else if("switch" == type){
        var opts = $.extend(true,{
            offText:"否",
            onText:"是",
        },option);
        $(id).switchbutton(opts);
    }
}

zUtil.elInit = function(id,type,option){
   if("tab" == type){
       var opts = $.extend(true,{
         border:false,
       },option);
       return $(id).tabs(opts);
   }
   else if(type.indexOf("tab-") != -1){
       type = type.split("-")[1];
       return $(id).tabs(type,option);
   }
   else if("menu" == type){
       var opts = $.extend(true,{
           disabled: true
       },option);
       var menu = $(id).menu(opts);
       if(opts.disabled){
           $(id).menu('show',opts);
       }
       return menu;
   }
   else if(type.indexOf("menu-") != -1){
       type = type.split("-")[1];
       return $(id).menu(type,option);
   }
   else if("accordion" == type){
       var opts = $.extend(true,{
         /*
           width     number     分类容器的宽度。     auto
           height     number     分类容器的高度。     auto
           fit     boolean     如果设置为true，分类容器大小将自适应父容器。     false
           border     boolean     定义是否显示边框。     true
           animate     boolean     定义在展开和折叠的时候是否显示动画效果。     true
           multiple     boolean     如果为true时，同时展开多个面板。（该属性自1.3.5版开始可用）     false
           selected     number     设置初始化时默认选中的面板索引号。（该属性自1.3.5版开始可用）     0
           halign     string
           */
       },option);
       return $(id).accordion(opts);
   }
   else if(type.indexOf("accordion-") != -1){
       type = type.split("-")[1];
       return $(id).accordion(type,option);
   }
   else if("layout" == type){
       var opts = $.extend(true,{
       },option);
       return $(id).layout(opts);
   }
   else if(type.indexOf("layout-") != -1){
       type = type.split("-")[1];
       return $(id).layout(type,option);
   }
   else if("panel" == type){
       var opts = $.extend(true,{
       },option);
       return $(id).panel(opts);
   }
   else if(type.indexOf("panel-") != -1){
       type = type.split("-")[1];
       return $(id).panel(type,option);
   }
}

/**赋值/取值**/
zUtil.valAll = function(id,data,options){
    var opts = $.extend(true, {
       clearForm: true,
       objcode: CCobjcode,
       arrayVal:true,
    }, options);
    var objcode =opts.objcode;
    if("undefined" === $.type(data)){
        function getValues(id,path,lv){
            data = {};
            var valfunc = function(ex,namex){
                var hasVal = zUtil.deepVal(data,namex);
                var currVal = zUtil.val(ex);
                if("undefined" === $.type(hasVal) || hasVal === null){
                    if($(ex).hasClass('checkbox-f') || "checkbox" === $(ex).prop('type')){
//                        console.log("1 >>>>>>"+namex);
//                        console.log(currVal);
                        data = zUtil.deepVal(data, namex, currVal!=null?[currVal]:null);
                    }else if($(ex).hasClass('radiobutton-f') || "radio" === $(ex).prop('type')){
//                        console.log("5 >>>>>>"+namex);
//                        console.log(currVal);
                        data = zUtil.deepVal(data, namex, currVal!=null?currVal:null);
                    }else{
//                        console.log("2 >>>>>>"+namex);
//                        console.log(currVal);
                        data = zUtil.deepVal(data, namex, currVal);
                    }
                }else{
                    if("array" === $.type(hasVal) && ($(ex).hasClass('checkbox-f') 
                         || "checkbox" === $(ex).prop('type'))){
//                        console.log("3 >>>>>>"+namex);
//                        console.log(currVal);
                        data = zUtil.deepVal(data, namex, $.merge(hasVal,currVal!=null?[currVal]:[]));
                    }else if($(ex).hasClass('radiobutton-f') || "radio" === $(ex).prop('type')){
//                        console.log("6 >>>>>>"+namex);
//                        console.log(currVal);
                        data = zUtil.deepVal(data, namex, currVal!=null?currVal:hasVal);
                    }else{
//                        console.log("4 >>>>>>"+namex);
//                        console.log(currVal);
                        data = zUtil.deepVal(data, namex, currVal);
                    }
                }
            }
            $(id).find(':input[class*=-f],table[class*=-f],table[name],:input[name],label[name],span[name]').not("[class*=-value]").each(function(i,e){
                var name = getElNameAll($(e));
                if(name){
                    var groups = $(e).parents('['+objcode+']');
                    if(groups.length > 0){
                        var gropupath2 = [];
                        for(var ig=groups.length-1;ig>=0;ig--){
                            var gkeys = $(groups[ig]).attr(objcode);
                            var keyarr = gkeys.split(".");
                            $.each(keyarr,function(idx,item){
                                gropupath2.push(item);
                            });
                        }
                        gropupath2.push(name);
                        valfunc(e,gropupath2);
                    }else{
                        valfunc(e,name);
                    }
                }
            });
        };
        
        getValues(id,data);
        
        if(opts.arrayVal && data){
           var handleArrVal = function(dt){
              $.each(dt,function(key,val){
                   if("array" === $.type(val)){
                      if(val.length === 0){
                          dt[key] = null;
                      }else if("object" === $.type(val[0])){
                         handleArrVal(val);
                      }else if("array" === $.type(val[0])){
                         handleArrVal(val);
                      }else {
                         dt[key] = val.toString();
                      }
                   } else if("object" === $.type(val)){
                       handleArrVal(val);
                   }
              });
           }
           
           handleArrVal(data);
        }
        return data;
    }else{
        if(opts.clearForm){
            zUtil.formClear(id);
        }
        function getParentsGroupLvl(e,neme){
            var groups = $(e).parents('['+objcode+']');
            if(groups.length > 0){
                var gropupath2 = [];
                for(var ig=groups.length-1;ig>=0;ig--){
                    gropupath2.push($(groups[ig]).attr(objcode));
                }
               return gropupath2.join(".");
            }
            return null;
        }
        function setValues(id,data,prelevel){
            var el = $(id);
            if("object" === $.type(data)){
                $.each(data,function(key,value){
                    if("undefined" === $.type(value)){
                        value = null;
                    }
                    
                    if(("array" !== $.type(value) && "object" !== $.type(value))
                        || ("array" === $.type(value) && value[0] && "object" !== $.type(value[0]))){
                        var cids = ':input[textboxname='+key+'],:input[radiobuttonname='+key+'],:input[checkboxname='+key+']'
                           +',:input[slidername='+key+'],:input[name='+key+'],label[name='+key+'],span[name='+key+']';
                        el.find(cids).not("[class*=-value]").each(function(i,e){
                            var glevel = getParentsGroupLvl(e,key);
//                            console.log("AA---"+prelevel+"-"+glevel);
                            if(glevel === prelevel){
                                zUtil.val(e,value);
                            }
                        });
                    }
                    else if("object" === $.type(value)){
                        var nlevel = prelevel != null?prelevel + "." + key:key;
                        setValues(el,value,nlevel);
                    }
                    else if("array" === $.type(value) && "object" === $.type(value[0])){
                        //肯定是表格赋值
                        var tableEl = el.find('table[name="'+key+'"]');
                        if(tableEl.length>0){
                            tableEl.each(function(i,e){
                                var glevel = getParentsGroupLvl(e,key);
                                if(glevel === prelevel){
                                    if($(e).is('[class*=-f]')){
                                        zUtil.val("#"+e.id,{total:value.length, rows: value});
                                    }else{//自定义表格
                                         
                                    }
                                    return false;
                                }
                            });
                        }
                    }
                });
            }
            else if("array" === $.type(data) && "object" === $.type(data[0])){
                //肯定是表格赋值
                var tableEl = el.find('table[name="'+key+'"]');
                if(tableEl.length>0){
                    tableEl.each(function(i,e){
                        var glevel = getParentsGroupLvl(e,key);
                        if(glevel === prelevel){
                            if($(e).is('[class*=-f]')){
                                zUtil.val("#"+e.id,{total:value.length, rows: value});
                            }else{//自定义表格
                                 
                            }
                            return false;
                        }
                    });
                }
            }
        }
        
        setValues(id,data,null);
    }
}
zUtil.val = function(id,val,options){
    var el = $(id);
    
    var tagName = el.prop("tagName");
    var type = el.prop("type");
    var name = getElNameAll(el);
    
      var opts = {
//            gFormat: function(name,value){},//指定格式转换为指定格式
//            gName: {xxx:转换方法, xxx:转换方法,...},//指定NAME转换为指定格式
//            sFormat: function(name,value){},//指定格式转换为指定格式
//            sName: {xxx:转换方法, xxx:转换方法,...},//指定NAME转换为指定格式
              arrayVal: true,
      };
      opts = $.extend(true,opts,options);
      
      var formatEx = function(keyName,keyVal,type){
          var convertEx = function(keyName,keyVal){
              if('undefined' !== $.type(opts[fname2]) && opts[fname2] !== null){
                  if(opts[fname2][keyName]){
                      return opts[fname2][keyName](keyVal,keyName);
                  }
              }
              if('undefined' !== $.type(opts[fname1]) && opts[fname1] !== null){
                  return opts[fname1](keyVal,keyName);
              }
              return keyVal;
          }
          try{
              var  fname1 = type?"gFormat":"sFormat";
              var  fname2 = type?"gName":"sName";
              if('array' === $.type(keyVal) && 'object' !== $.type(keyVal[0])){
                  var newArr = [];
                  $.each(keyVal,function(i,ival){
                      newArr.push(convertEx(keyName,ival));
                  });
                  return newArr;
              }else{
                  return convertEx(keyName,keyVal);
              }
          }catch(b){
              
          }
          return keyVal;
    };
    
    if("undefined" === $.type(val)){
        val = null;
        
        if("LABEL" === tagName || "SPAN" === tagName){
            val = el.html();
        }
        else if("TABLE" === tagName && el.hasClass('datagrid-f')){
            return zUtil.tableData(id)["rows"];
        }
        else if("TABLE" === tagName){
            //自定义表格
        }
        else if(el.hasClass('tagbox-f')){
            if(el.tagbox('options').multiple){
                val = el.tagbox('getValues');
            }else{
                val = el.tagbox('getValue');
            }
        }
        else if(el.hasClass('combogrid-f')){
            var copts = el.combogrid('options');
            if(copts.multiple){
                val = el.combogrid('getValues');
            }else{
                val = el.combogrid('getValue');
            }
        }
        else if(el.hasClass('combobox-f')){
            if(el.combobox('options').multiple){
                val = el.combobox('getValues');
            }else{
                val = el.combobox('getValue');
            }
        }
        else if(el.hasClass('checkbox-f')){
            var copts = el.checkbox('options');
            if(copts.checked){
                 val = el.checkbox('options').value;
            }
        }
        else if(el.hasClass('radiobutton-f')){
            var copts = el.radiobutton('options');
            if(copts.checked){
                val = el.radiobutton('options').value;
            }
        }
        else if(el.hasClass('slider-f')){
            var copts = el.slider('options');
            if(copts.range){
                val = el.slider('getValues');
            }else{
                val = el.slider('getValue');
            }
        }
        else if(el.hasClass('passwordbox-f')){
            val = el.textbox('getValue');
        }
        else if(el.hasClass('textbox-f')){
            val = el.textbox('getValue');
        }
        else if("undefined" !== $.type(tagName)) {
            if("SELECT" === tagName){
                val = el.val();
            }else if("INPUT" === tagName){
                if("checkbox" === type){
                    var ckStatus = el.prop('checked');
                    if("undefined"!== $.type(ckStatus) && ckStatus){
                        val =  el.val();
                    }
                }else if("radio" === type){
                    var ckStatus = el.prop('checked');
                    if("undefined"!== $.type(ckStatus) && ckStatus){
                        val =  el.val();
                    }
                }else {
                    val = el.val();
                }
            }else if("TEXTAREA" === tagName){
                val = el.val();
            }else{
                val = el.val();
            }
        }
        val = formatEx(name,val,true);
        if(opts.arrayVal && "array" === $.type(val)){
            val = val.length>0 ? val.toString() : null;
        }
        if(val === ""){
          val = null;
        }
        return val;
    }else{
        val = formatEx(name,val,false);
        
        if("LABEL" === tagName || "SPAN" === tagName){
            el.html(val);
        }
        else if("TABLE" === tagName && el.hasClass('datagrid-f')){
            zUtil.tableData(id,val);
        }
        else if("TABLE" === tagName){
            //自定义表格
        }
        else if(el.hasClass('tagbox-f')){
            var copts = el.tagbox('options');
            if(copts.multiple){
                el.tagbox('setValues',val?val:[]);
            }else{
                el.tagbox('setValue',val);
            }
        }
        else if(el.hasClass('combogrid-f')){
            var copts = el.combogrid('options');
            if(copts.multiple){
                el.combogrid('setValues',val?val:[]);
            }else{
                el.combogrid('setValue',val);
            }
        }
        else if(el.hasClass('combobox-f')){
            var copts = el.combobox('options');
            if(copts.multiple){
                el.combobox('setValues',val?val:[]);
            }else{
                el.combobox('setValue',val);
            }
        }
        else if(el.hasClass('checkbox-f')){
            if("array" === $.type(val)){
                if(val.indexOf((el.checkbox('options').value))!=-1){
                    el.checkbox('check');
                }
            }else{
                if(val == el.checkbox('options').value){
                    el.checkbox('check');
                }
            }
        }
        else if(el.hasClass('radiobutton-f')){
            if(val == el.radiobutton('options').value){
                el.radiobutton('check');
            }
        }
        else if(el.hasClass('slider-f')){
            var copts = el.slider('options');
            if(copts.range){
                el.slider('setValues',val?val:[]);
            }else{
                el.slider('setValue',val);
            }
        }
        else if(el.hasClass('passwordbox-f')){
            el.textbox('setValue',val);
        }
        else if(el.hasClass('combo-f')){
            var copts = el.combo('options');
            if(copts.multiple){
                el.combo('setValues',val?val:[]);
            }else{
                el.combo('setValue',val);
            }
        }
        else if(el.hasClass('textbox-f')){
            el.textbox('setValue',val);
        }
        else if("undefined" !== $.type(tagName)) {
            if("SELECT" === tagName){
                el.val(val);
            }else if("INPUT" === tagName){
                if("checkbox" === type){
                    if(val && ("array" === $.type(val) || "string" === $.type(val))){
                        if("string" === $.type(val)){
                            val = val.split(",");
                        }
                        $.each(val,function(i,item){
                            if(el.is('[value='+item+']')){
                                el.prop('checked','true');
                            }
                        });
                    }
                }else if("radio" === type){
                    if(el.is('[value='+val+']')){
                        el.prop('checked','true');
                    }
                }else{
                    el.val(val);
                }
            }else if("TEXTAREA" === tagName){
                el.val(val);
            }else{
                el.val(val);
            }
        }
    }
};

zUtil.readonlyAll = function(id,flag){
    var el = $(id);
    el.find(':input[class*=-f],table[class*=-f],table[name],:input[name]').not("[class*=-value]").each(function(i,e){
        zUtil.readonly(e,flag);
    });
};
zUtil.readonly = function(id,flag){
    flag = "undefined" === $.type(flag)?true:flag;
    var el = $(id);
    var tagName = el.prop("tagName");
    var type = el.prop("type");
    
    if(el.hasClass('tagbox-f')){
        flag ? el.next().attr('disabled','disabled'):el.next().removeAttr('disabled');
        el.tagbox('readonly', flag);
    }else if(el.hasClass('combogrid-f')){
        el.combobox('readonly', flag);
    }else if(el.hasClass('combobox-f')){
        el.combobox('readonly', flag);
    }else if(el.hasClass('checkbox-f')){
        flag ? el.parent('div').attr('disabled','disabled'):el.parent('div').removeAttr('disabled');
        el.checkbox(flag?'disable':'enable');
    }else if(el.hasClass('radiobutton-f')){
        flag ? el.parent('div').attr('disabled','disabled'):el.parent('div').removeAttr('disabled');
        el.radiobutton(flag?'disable':'enable');
    }else if(el.hasClass('slider-f')){
        flag ? el.parent("div").attr('disabled','disabled'):el.parent('div').removeAttr('disabled');
        el.slider(flag?'disable':'enable');
    }else if(el.hasClass('combo-f')){
        el.combo('readonly', flag);
    }else if(el.hasClass('textbox-f')){
        el.textbox('readonly', flag);
    } else if(el.hasClass('datagrid-f')){
        var tableobj = el.parent();
        var tablebtn = tableobj.find('td[field=buttonArr]');
        var toolbar = tableobj.prev('.datagrid-toolbar');
        flag ? toolbar.attr('disabled','disabled'):toolbar.removeAttr('disabled');
        if(toolbar.length>0){
            flag ? toolbar.children().css("display","none"):toolbar.children().css('display','unset');
        }
        if(tablebtn.length>0){
            flag ? tablebtn.css("display","none"):tablebtn.css("display",'unset');
        }
    }
    else if("TABLE" === tagName){
        
    }
    else {
        if("SELECT" === tagName || "checkbox" === type || "radio" === type){
            flag ? el.parent('div').attr('disabled','disabled'):el.parent('div').removeAttr('disabled');
            flag ? el.addClass('disabled'):el.removeClass('disabled');
        }
        flag ? el.attr('readonly','true'):el.removeAttr('readonly');
    }
};

zUtil.areaSize = function(id,options){
    if("undefined" !== $.type(id)){
        id = id + ' textarea';
    }else{
        id = ' textarea';
    }
    var opts = $.extend({
//            width: '100%',
            maxWidth: '100%',
            handles: 's',
            edge: 15,
            minHeight: 30,
            onStopResize: function(e){
                $(e.target).children('textarea').css({'height':'100%','width':'100%'});
            }
    },options);
    
    if($(id).parent('.textbox.easyui-fluid').length>0){
        $(id).parent('.textbox.easyui-fluid').resizable(opts);
        $(id).parent('.textbox.easyui-fluid').addClass("spsnarea");
    }
    $(id).not('.textbox-text').resizable(opts);
}